package com.ddd.mill.domain.aggregate.dictionary;

import com.ddd.mill.domain.aggregate.dictionary.repository.DictionaryRepository;
import com.ddd.mill.domain.aggregate.dictionary.valueobject.DictionaryUnitListVo;
import com.ddd.mill.infrastructure.persistent.domain.BaseAggregate;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import com.ddd.mill.domain.aggregate.dictionary.entity.Dictionary;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author liu
 * @title: DictionaryAggregate
 * @projectName trading-center
 * @date 2020/11/3015:26
 */
@Slf4j
@Service
public class DictionaryAggregate extends BaseAggregate {
    @Resource
    DictionaryRepository dictionaryRepository;

    public List<DictionaryUnitListVo> unitList(){
        List<Dictionary> dictionaryList =dictionaryRepository.unitList();
        List<DictionaryUnitListVo> dictionaryResponseList = new ArrayList<>();
        for (Dictionary d : dictionaryList){
            DictionaryUnitListVo dictionaryResponse = new DictionaryUnitListVo();
            dictionaryResponse.setId(d.getId());
            dictionaryResponse.setName(d.getVal());
            dictionaryResponseList.add(dictionaryResponse);
        }
        return dictionaryResponseList;
    }
}
